import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:im_base/public/tim/model/menu_data.dart';
import '../../../../service/tim_config.dart';
import 'logic.dart';
import 'state.dart';

//更多操作菜单
class MenusWidget extends StatelessWidget {
 late final MenusLogic logic;
  late final MenusState state;
  MenusWidget(String? id){
    logic = Get.put(MenusLogic(),tag: id);
    state =logic.state;
    state.id=id;
  }
  @override
  Widget build(BuildContext context) {
    var menus = List<Widget>.empty(growable: true);
    menus.addAll(menuList.map((e) => menuItem(e)).toList());
    menus.addAll(TimConfig.instance.getMoreMenus());
    log('MenusWidget---${menus.length}');
    int count = menus.length > 4 ? 4 : menus.length;
    return Container(
      width: double.infinity,
      height: 200,
      alignment: Alignment.center,
      child: GridView(
        physics: NeverScrollableScrollPhysics(),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            mainAxisExtent: 100, crossAxisCount: count),
        children: menus,
      ),
    );
  }

  Widget menuItem(MenuData e) {
    return InkWell(
      key: Key(e.icon),
      onTap: () => logic.operateMenu(e.type),
      child: Container(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: 50,
              height: 50,
              margin: EdgeInsets.only(bottom: 3),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(12)),
              child: Image.asset(
                e.icon,
                fit: BoxFit.contain,
              ),
            ),
            Text(
              e.title,
              style: TextStyle(color: Colors.black87, fontSize: 12),
            )
          ],
        ),
      ),
    );
  }
}
